import axios from '@/utils/request.ts'
import { FormModel, getUserInfoRes, LoginRes, RegisterRes, updateAvatarRes } from "@/api/user/type.ts";

/**
 * 登录请求
 */
export const loginReq = (data: FormModel) => axios.post<FormModel, LoginRes>('/user/login', {
    username: data.username,
    password: data.password,
})

/**
 * 注册请求
 */
export const registerReq = (data: FormModel) => axios.post<FormModel, RegisterRes>('/user/register', {
    username: data.username,
    password: data.password,
    confirmPassword: data.confirmPassword,
})

/**
 * 获取用户信息
 */
export const getUserInfoReq = () => axios.get<null, getUserInfoRes>('/user/info')

/**
 * 更新头像
 */
export const updateAvatarReq = (file: File) => {
    const formData = new FormData();
    formData.append('avatar', file);
    return axios.post<File, updateAvatarRes>('/upload', formData, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

/**
 * 更新用户名
 */
export const updateUsernameReq = (username: string) => axios.put<string, any>('/user/username', {
}, {
    params: {
        username
    }
});

/**
 * 更新自我介绍
 */
export const updateIntroductionReq = (introduction: string) => axios.put<string, any>('/user/introduction', {
    introduction
})
